<?php

namespace FacebookAction;

require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/GraphUser.php' );
require_once( 'Facebook/GraphSessionInfo.php' );

use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookAuthorizationException;
use Facebook\GraphObject;
use Facebook\GraphUser;
use Facebook\GraphSessionInfo;

class FacebookInfo {
    //---------------------------- lay ve thong tin cua admin ------------------
    public function getInfoAdmin($session) {
        try {
            $request = new FacebookRequest(
                    $session, 'GET', '/me'
            );
            $response = $request->execute();
            $graphObject = $response->getGraphObject()->asArray();
            $my_json = json_encode((array) $graphObject);
            print_r($my_json);
            $json_return = json_decode($my_json, TRUE);
            return $json_return;
        } catch (FacebookRequestException $e) {

            echo "Exception occured, code: " . $e->getCode();
            echo " with message: " . $e->getMessage();
        }
    }
    
    //-------------------- lay ve thong tin cua mot doi tuong ----------------
    public function getInfoObject($session, $object_id) {
        try {
            $request = new FacebookRequest(
                    $session, 'GET', '/' . $object_id
            );
            $response = $request->execute();
            $graphObject = $response->getGraphObject()->asArray();
            $my_json = json_encode((array) $graphObject);
            print_r($my_json);
            $json_return = json_decode($my_json, TRUE);
            return $json_return;
        } catch (FacebookRequestException $e) {

            echo "Exception occured, code: " . $e->getCode();
            echo " with message: " . $e->getMessage();
        }
    }
    
    
}
    